package cn.lg.soar.system.biz.modules.auth.mapper;

import cn.lg.soar.system.biz.modules.auth.entity.DataScope;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author luguoxiang
 * @since 2022-04-30
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public interface DataScopeMapper extends BaseMapper<DataScope> {

    @Select("SELECT a.role_id, a.rule_id FROM lg_sys_data_scope a INNER JOIN lg_sys_resource b ON a.resource_id=b.id " +
            "WHERE b.`code`=#{resourceCode} AND b.disabled=0 " +
            "UNION ALL " +
            "SELECT 0 as role_id, a.id AS rule_id FROM lg_sys_data_rule a INNER JOIN lg_sys_resource b ON a.resource_id=b.id " +
            "WHERE a.defaulted=1 AND b.`code`=#{resourceCode} AND b.disabled=0")
    List<DataScope> listByResourceCode(String resourceCode);

}
